﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.IDAL.Mtbl;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.DALFactory;
using HKEA.CMS.Core.Utility;

namespace HKEA.CMS.Core.BLL.Mtbl
{
    public class mtblActiviteTypeBLL
    {
        private ImtblActiviteType IDAL;
        public mtblActiviteTypeBLL()
        {
            IDAL = DataAccess.CreateActivityType();
        }

        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static mtblActiviteTypeBLL GetInstance()
        {
            return new mtblActiviteTypeBLL();
        }

        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int InsertENT(mtblActiviteType ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret= IDAL.InsertENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 物理删除
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int DeleteENT(mtblActiviteType ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.DeleteENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 修改记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int UpdateENT(mtblActiviteType ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.UpdateENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        public int SaveList(List<mtblActiviteType> ToAdd, List<mtblActiviteType> ToUpdate, List<int> ToDel, string LastModifyBy)
        {
            int ret = 0;
            try
            {
                ret = IDAL.SaveList(ToAdd, ToUpdate, ToDel, LastModifyBy);
            }
            catch (Exception er)
            { }
            return ret;
        }
        /// <summary>
        /// 根据条件得到符合条件的结果集，带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<mtblActiviteType> GetListByENT(mtblActiviteType ent, PageParam param, string strPropertyName, string strOrderBy)
        {
            List<mtblActiviteType> list = new List<mtblActiviteType>();
            if (ent != null && param != null)
            {
                try
                {
                    list = IDAL.GetListByENT(ent, param, strPropertyName, strOrderBy);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }

        public mtblActiviteType GetEntity(mtblActiviteType ent)
        {
            var list = GetListByENT(ent);
            if (list != null)
                return list.FirstOrDefault();
            return null;
        }

        /// <summary>
        /// 根据条件得到符合条件的结果集，不带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public List<mtblActiviteType> GetListByENT(mtblActiviteType ent)
        {
            List<mtblActiviteType> list = new List<mtblActiviteType>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListByENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }

        /// <summary>
        /// 根据ActivityTypeCode查询来源于 HKEA 的所有ActivityType;
        /// </summary>
        /// <param name="HKEACode"></param>
        /// <returns>Code为空时，返回所有来源HKEA的数据，否则按Code查询</returns>
        public List<mtblActiviteType> GetHKEAListByENT(string HKEACode)
        {
            List<mtblActiviteType> list = new List<mtblActiviteType>();
            try { list = IDAL.GetHKEAListByENT(HKEACode); }
            catch (Exception) { }
            return list;
        }

        /// <summary>
        /// 根据条件得到符合条件的记录条数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int GetCountByENT(mtblActiviteType ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.GetCountByENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 判断是否已存在符合条件的记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public bool IsExist(mtblActiviteType ent)
        {
            bool ret = false;
            if (ent != null)
            {
                if (GetCountByENT(ent) > 0)
                    ret = true;
            }
            return ret;
        }
    }
}
